﻿@{
    ViewBag.Title = "岗位管理";
    Layout = "~/Areas/Member/Views/Shared/_Layout.cshtml";
}

<div class="layui-tab layui-tab-brief" lay-filter="user">
    <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 5px 0;">
        <form action="" class="layui-form">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" name="keyWord" class="layui-input" value="@ViewBag.Keyword" placeholder="请输入名称搜索">
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <button type="button" class="layui-btn searchButton">搜索</button>
                    <a class="layui-btn" href="javascript:ShowPage('/Management/Position/Create','添加岗位',6)">添加岗位</a>
                </div>
            </div>
        </form>
    </div>
    <table class="layui-table" lay-data="{url:'/Management/Position/GetData', cellMinWidth: 80, page: true,limit:15}" id="resultList" lay-filter="resultList">
        <thead>
            <tr>
                <th lay-data="{field:'ID', width:80, align:'center'}">ID</th>
                <th lay-data="{ field: 'Name',edit: 'text'}">名称</th>
                <th lay-data="{field:'DepartmentFullPath', width:300}">部门</th>
                <th lay-data="{field:'Sort',edit:'text',type:'mynumbers', width:60}">排序</th>
                <th lay-data="{width:80,toolbar: '#status'}">状态</th>
                <th lay-data="{fixed: 'right', width:120, align:'center', toolbar: '#barDemo'}">操作</th>
            </tr>
        </thead>
    </table>
    <script type="text/html" id="status">
        {{# if(d.Status==-1){ }}
        已禁用
        {{# } else{ }}
        正常
        {{# } }}
    </script>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-primary layui-btn-xs" href="javascript:ShowPage('/Management/Position/Edit?id={{d.ID}}','编辑岗位',6)" >编辑</a>
        {{# if(d.Status==-1){ }}
        <a class="layui-btn layui-btn-primary layui-btn-xs" href="javascript:enabledItem({{d.ID}})">启用</a>
        {{# } else{ }}
        <a class="layui-btn layui-btn-primary layui-btn-xs" href="javascript:disEnabledItem({{d.ID}})">禁用</a>
        {{# } }}

    </script>

</div>



<script type="text/javascript">
    function enabledItem(id) {
        layer.confirm('您确认启用当前岗位吗？', {
            btn: ['我要启用', '不小心点错了'], title: '岗位启用确认' //按钮
        }, function () {
            var url = "/Management/Position/Enabled?id=" + id;
            $.getJSON(url, function (data) {
                if (data.State === 200) {
                    layer.msg("岗位启用成功!");
                    $(".layui-laypage-btn")[0].click();
                }
                else {
                    layer.msg(data.Message);
                }
            });
        }, function () {

        });
    }
    function disEnabledItem(id) {
        layer.confirm('您确认禁用当前岗位吗？', {
            btn: ['我要禁用', '不小心点错了'], title: '岗位禁用确认' //按钮
        }, function () {
            var url = "/Management/Position/DisEnabled?id=" + id;
            $.getJSON(url, function (data) {
                if (data.State === 200) {
                    layer.msg("岗位禁用成功!");
                    $(".layui-laypage-btn")[0].click();
                }
                else {
                    layer.msg(data.Message);
                }
            });
        }, function () {

        });
    }

    layui.use('table', function () {
        var table = layui.table;       
        table.on('edit(resultList)', function (obj) {
            if (obj.field === 'Name') {
                var url = "/Management/Position/SetName?id=" + obj.data.ID + "&name=" + obj.value;
                $.getJSON(url, function (data) {
                    if (data.State == 200) {
                        layer.msg("岗位名称修改成功", { time: 500 });
                    }
                    else {
                        layer.msg(data.Message);
                    }
                });
            }
            else if (obj.field === 'Sort') {
                var url = "/Management/Position/SetSort?id=" + obj.data.ID + "&sort=" + obj.value;
                $.getJSON(url, function (data) {
                    if (data.State == 200) {
                        layer.msg("排序修改成功", { time: 500 });
                    }
                    else {
                        layer.msg(data.Message);
                    }
                });
            }
        });

    });

</script>


